package org.example.hadoop.service.authorRatingScoreSort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.example.hadoop.domain.AuthorCountBean;
import org.example.hadoop.domain.AuthorRatingScoreAvgBean;

import java.io.IOException;

/**
 * @author wwy
 * @date 2020-11-10 19:52
 */
public class AuthorRatingScoreSortMapper extends Mapper<LongWritable, Text, AuthorRatingScoreAvgBean, Text> {
    /**
     * k1     v1
     *        余华 9.8
     * k2                   v2
     *
     * AuthorRatingScoreAvgBean      余华，aa,bb
     * @param key
     * @param value
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] valueArray = line.split("\t");
        String authorName = valueArray[0];
        double count = Double.parseDouble(valueArray[1]);
        AuthorRatingScoreAvgBean authorRatingScoreAvgBean = new AuthorRatingScoreAvgBean();
        authorRatingScoreAvgBean.setCount(count);
        context.write(authorRatingScoreAvgBean,new Text(authorName));
    }
}
